import java.util.ArrayList;
import java.util.Scanner;


public class OutgoingManager
{
   int customerID;
   
   public OutgoingManager(int ci)
   {
      customerID = ci;
   }
   
   public void processRequest()
   {
      CustomerAccount account = Accounts.retrieveAccount(customerID);
      
      Scanner in = new Scanner(System.in);
      if(account.getState().getItem())
      {

	      System.out.println("Choose an option: \n" +
	            "\t1. Buy a Movie\n" +
	            "\t2. Rent a Movie\n");
	      int requestChoice = in.nextInt();
	      
	      boolean process = true;
	      while(process)
	      {
	      
	         ArrayList<Items> items;
	         switch (requestChoice)
	         {
	            case 1: items = Inventory.getPurchasableItems(); break;
	            case 2: items = Inventory.getBorrowableItems(); break;
	            default: items = null; return;
	         }
	         
	         if(items != null && items.size() > 0)
	         {
	            System.out.println("Choose a movie: ");
	            displayItems(items);
	            int movieChoice = in.nextInt();
	            
	            switch (requestChoice)
	            {
	               case 1: items.get(movieChoice).buyItem(account); break;
	               case 2: items.get(movieChoice).borrowItem(account); break;
	               default: return;
	            }
	            
	            System.out.println("Choose an option: \n" +
	                  "\t 1. To Continue\n" +
	                  "\t-1. To Quit\n");
	           int continueChoice = in.nextInt();
	           
	           if(continueChoice == -1)
	           {
	              process = false;
	           }
	         }
	         else
	         {
	            System.out.println("No items avalibale for choice " + requestChoice);
	            break;
	         }
	      }
	      
	      switch (requestChoice)
	      {
	         case 1: new BuyPayment(account).processPayment(); break;
	         case 2: new RentPayment(account).processPayment(); break;
	         default: return;
	      }
      }
   }

   private void displayItems(ArrayList<Items> items)
   {
      for(int i = 0; i < items.size(); i++)
         System.out.println("\t" + i + ". " + items.get(i).getName());
   }
}